//define parameter pin 
int DLock=9; 
int lamp=10; 
int DState=11;  

void setup(){         //setup for read input   
Serial.begin(9600);   //configure input/output   
pinMode(DLock,OUTPUT);    
pinMode(lamp,OUTPUT);   
pinMode(DState,INPUT);  }  

void loop(){   
if (Serial.available()) {     
char enter = Serial.read(); //input commands 'L' or 'U'          

//analyse the input command respect to the case     
switch (enter) {       //enter input 'L' to lock the door       

case 'L':       //if the door is closed       
if(digitalRead(DState)==HIGH){         
digitalWrite(DLock,HIGH);          
digitalWrite(lamp,HIGH); //lamp blinking 1 second         
delay(1000);         
digitalWrite(lamp,LOW);       }       //if the door is opened       
else{         
Serial.println("OPEN"); //nothing      
}        
break;              //enter input 'U' to unlock the door       

case 'U':       //if the door is closed       
if(digitalRead(DState)==HIGH){         
digitalWrite(DLock,LOW); //LED not light up state the door is unlock         
digitalWrite(lamp,HIGH); //lamp blinking twice         
delay(1000);         
digitalWrite(lamp,LOW);         
delay(1000);         
digitalWrite(lamp,HIGH);         
delay(1000);         
digitalWrite(lamp,LOW);       }       //if the door is opened       
else{         
Serial.println("OPEN"); //nothing      
}              
break;     
}   
} 
} 
